package com.example.sofa_module;


import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TableLayout;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentStatePagerAdapter;
import androidx.lifecycle.Observer;
import androidx.viewbinding.ViewBinding;

import com.example.common.EvenBusAction;
import com.example.common.databus.LiveDataBus;
import com.example.common.mvvm.view.BaseFragment;
import com.example.sofa_module.databinding.FragmentSofaBinding;
import com.flyco.tablayout.listener.OnTabSelectListener;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class SofaFragment extends BaseFragment<FragmentSofaBinding,SofaViewModel> {
    private List<Fragment> list=new ArrayList<>();
    private List<String>title=new ArrayList<>();
    private boolean loadData=false;
    @Override
    public View bindLayout() {
        return v.getRoot();
    }

    @Override
    public ViewBinding initBinding() {
        FragmentSofaBinding binding= FragmentSofaBinding.inflate(inflater);
        return binding;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Window window = getActivity().getWindow();
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            window.getDecorView().setSystemUiVisibility(
                     View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                     |View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                     |View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                    | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            //先将状态栏调整为透明
            window.setStatusBarColor(Color.WHITE);
        }
        list.add(new TabFragment());
        list.add(new TabFragment());
        list.add(new TabFragment());
        title.add("图片");
        title.add("视频");
        title.add("文本");

    }

    @Override
    public void initView() {
        TabAdapter tabAdapter = new TabAdapter(getChildFragmentManager(), FragmentStatePagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT, list, title);
        v.sodaVp.setAdapter(tabAdapter);
        v.sofaTab.setViewPager(v.sodaVp);
        v.sofaTab.setTextSelectColor(Color.parseColor("#FF86A6"));
        v.sofaTab.setTextUnselectColor(Color.parseColor("#2D2D2D"));
        v.sofaTab.setIndicatorColor(Color.parseColor("#FF86A6"));
        v.sofaTab.setIndicatorWidth(10);
        v.sofaTab.setOnTabSelectListener(new OnTabSelectListener() {
            @Override
            public void onTabSelect(int position) {
                EvenBusAction evenBusAction = new EvenBusAction();
                evenBusAction.action="selectTab";
                Map<String,Object>map=new HashMap<>();
                map.put("position",position);
                evenBusAction.map=map;
                EventBus.getDefault().post(evenBusAction);

            }

            @Override
            public void onTabReselect(int position) {

            }
        });
    }


    @Override
    public void initData() {

    }

}
